/********************************************************************
Name: Table A2: Sheriff Election Characteristics
Author: Dan Thompson
Date: August 2019
Notes:
********************************************************************/

* Set the working directory 
gl root = "$sanctuary_root"
gl root = "YOUR_WORKING_DIRECTORY"

* Bring in the analysis dataset
use "$root/data/elections descriptive analysis data.dta", clear

* Focus on the places where we should see elections
keep if expected==1

* Make the state partisan control data long
foreach v in governor_dem house_dem_share senate_dem_share {
	gen `v' = .
	replace `v' = `v'2015 if year==2016
	forval y=2000/2015{
		replace `v' = `v'`y' if year==`y'
		drop `v'`y'
	}
}

* Calculate descriptives about the electoral environment
append using "$root/data/house elections descriptives.dta"
replace percent = percent/100

* Row 1
sum max_dem if partisan_gathered==1
sum max_dem if large_partisan_gathered==1
sum max_dem if house_elec==1

* Row 2
sum max_rep if partisan_gathered==1
sum max_rep if large_partisan_gathered==1
sum max_rep if house_elec==1

* Row 3
sum both_parties if partisan_gathered==1
sum both_parties if large_partisan_gathered==1
sum both_parties if house_elec==1

* Row 4
sum num_cands1 if partisan_gathered==1
sum num_cands1 if large_partisan_gathered==1
sum num_cands1 if house_elec==1

* Row 5
sum num_cands2 if partisan_gathered==1
sum num_cands2 if large_partisan_gathered==1
sum num_cands2 if house_elec==1

* Row 6
sum num_cands3 if partisan_gathered==1
sum num_cands3 if large_partisan_gathered==1
sum num_cands3 if house_elec==1

* Row 7
sum percent if partisan_gathered==1
sum percent if large_partisan_gathered==1
sum percent if house_elec==1

* Rows 8 and 9
unique state county if partisan_gathered==1
unique state county if large_partisan_gathered==1
count if house_elec==1
